package com.ai.bitcoin.util;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;


/**
 * 
 *
 */
public abstract class CommonUtil {
	
	/**
	 * 
	 * @param message
	 * @return
	 */
	public static String md5(String message) {
		if (StringUtils.isBlank(message)) {
			return null;
		}
		
		return DigestUtils.md5Hex(message);
	}
	
	public static String genetateProductListKey(Map<String, Object> map){
		
		Integer pageStart = (Integer)map.get("pageStart");
		Integer pageSize = (Integer)map.get("pageSize");
		Integer channelId = (Integer)map.get("channelId");
		
		StringBuffer sb = new StringBuffer();
		sb.append("product_list_");
		
		if(pageStart != null && pageSize != null){
			if(channelId != null){
				sb.append(channelId+"_").append(pageSize+"_").append(pageStart);
			}else{
				sb.append(pageSize+"_").append(pageStart);
			}
			
		}else{
			if(channelId != null){
				sb.append(channelId);
			}
		}
		
		return sb.toString();
	}

}
